<?php
// Adds PDF headers
header("Content-type: application/pdf");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <title></title>
    </head>
    <body>
        <?php
        require_once "functions.php";
// getting the id from the previous page (Nathalie)
        $p_id=$_GET['paper_id'];
        $paper_id=mysql_real_escape_string($p_id);
// Selecting version_id and path and ordering them descendingly to get the latest one
        $Latest_Version=mysql_query("SELECT version_id, path
                FROM version WHERE paper_id = '$paper_id' ORDER BY version_id DESC");
// Calls the path
        $row=mysql_fetch_assoc($Latest_Version);
        $data=formatText_safe($row['path']);
// Opens and reads the file
        $handle=fopen($data,'r');
        $contents=fread($handle,filesize($data));
        fclose($handle);
//Display PDF
        echo $contents;
        ?>
    </body>
</html>
